// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <iostream>

#include <pollux/vector/flat_vector.h>
#include <pollux/vector/fuzzer/generator_spec.h>
#include <tests/vector/fuzzer/examples/Utils.h>

using namespace kumo::pollux;
using namespace generator_spec_maker;
using namespace generator_spec_examples;

int main() {
  // This example shows how to use our GeneratorSpec class to generate vectors
  // of maps with user defined distributions.

  constexpr size_t sampleSize = 10000;
  constexpr int32_t lo = 0, hi = 10;
  constexpr double mu = 5.0, sigma = 2.0;
  constexpr size_t mapSizeLo = 5, mapSizeHi = 10;

  auto lengthDist =
      std::uniform_int_distribution<int32_t>(mapSizeLo, mapSizeHi);
  auto uniform = std::uniform_int_distribution<int32_t>(lo, hi);
  auto normal = std::normal_distribution<double>(mu, sigma);

  FuzzerGenerator rng;
  memory::MemoryManager::initialize({});
  auto pool = memory::memoryManager()->addLeafPool();

  GeneratorSpecPtr randomMap =
      RANDOM_MAP(RANDOM_INTEGER(uniform), RANDOM_DOUBLE(normal), lengthDist);
  VectorPtr vector = randomMap->generateData(rng, pool.get(), sampleSize);
  MapVector* map_vector = vector->as<MapVector>();
  auto uniformVector = map_vector->mapKeys();
  auto normalVector = map_vector->mapValues();

  std::cout
      << "Keys in random MapVector. Data generated from uniform distribution:\n"
      << plotVector(uniformVector->as_flat_vector<int32_t>()) << "\n";

  std::cout
      << "Values in random MapVector. Data generated from normal distribution:\n"
      << plotVector(normalVector->as_flat_vector<double>()) << "\n";

  return 0;
}
